getClosestFrameOrDialogAncestor

Returns the nearest Frame or JDialog that is an ancestor to the given component. If no JDialog or Frame is found then return the top-most component ancestor.